<?php include('header.php'); ?>

<?php

$title			= array('name'=>'title', 'id'=>'title', 'value' => set_value('title', $title));
$enable_on		= array('name'=>'enable_on', 'id'=>'enable_on', 'value'=>set_value('enable_on', set_value('enable_on', $enable_on)));
$disable_on		= array('name'=>'disable_on', 'id'=>'disable_on', 'value'=>set_value('disable_on', set_value('disable_on', $disable_on)));
$f_image		= array('name'=>'image', 'id'=>'image');
$link			= array('name'=>'link', 'value' => set_value('link', $link));	
$new_window		= array('name'=>'new_window', 'value'=>1, 'checked'=>set_checkbox('new_window', 1, $new_window));
?>

<?php echo form_open_multipart($this->config->item('admin_folder').'/boxes/form/'.$id); ?>
	<label for="title"><?php echo lang('title');?> </label>
	<?php echo form_input($title); ?>

    <label for="object"><?php echo lang('object');?> </label>
    <div>
        <div class="row">
            <div class="span5">
                <label><strong><?php echo lang('select_a_product');?></strong></label>
            </div>
        </div>
        <div class="row">
            <div class="span3" style="text-align:center">
                <div class="row">
                    <div class="span3">
                        <input class="span3" type="text" id="object_search" />
                        <script type="text/javascript">
                            $('#object_search').keyup(function(){
                                $('#object_list').html('');
                                run_object_query();
                            });

                            function run_object_query()
                            {
                                $.post("<?php echo site_url($this->config->item('admin_folder').'/boxes/object_autocomplete/');?>", { name: $('#object_search').val(), limit:10},
                                        function(data) {

                                            $('#object_list').html('');

                                            $.each(data, function(index, value){

                                                //if($('#related_object_'+index).length == 0)
                                                //{
                                                    $('#object_list').append('<option id="object_item_'+index+'" value="'+index+'">'+value+'</option>');
                                                //}
                                            });

                                        }, 'json');
                            }
                        </script>
                    </div>
                </div>
                <div class="row">
                    <div class="span3">
                        <select class="span3" id="object_list" size="5" style="margin:0px;"></select>
                    </div>
                </div>
                <div class="row">
                    <div class="span3" style="margin-top:8px;">
                        <a href="#" onclick="add_object_route();return false;" class="btn" title="Select Object"><?php echo lang('add_object_link');?></a>
                        <script type="text/javascript">
                            function add_object_route(){
                                if($('#object_list').val() != null)
                                {
                                    $.post("<?php echo site_url($this->config->item('admin_folder').'/boxes/get_route/');?>", { route_id: $('#object_list').val()},
                                            function(data) {

                                                $.each(data, function(index, value){

                                                       $("#link-text").val(value);

                                                });

                                            }, 'json');
                                }
                                else
                                {
                                    alert('<?php echo lang('alert_select_product');?>');
                                }
                            }
                        </script>
                    </div>
                </div>
            </div>

        </div>
    </div>

	<label for="link"><?php echo lang('link');?> </label>
    <input type="text" name="link" id="link-text" value="<?php echo $link['value']; ?>">
	<label for="enable_on"><?php echo lang('enable_on');?> </label>
	<?php echo form_input($enable_on); ?>

	<label for="disable_on"><?php echo lang('disable_on');?> </label>
	<?php echo form_input($disable_on); ?>
	
	<label class="checkbox">
	    <?php echo form_checkbox($new_window); ?> <?php echo lang('new_window');?>
	</label>

	<label for="image"><?php echo lang('image');?> </label>
	<?php echo form_upload($f_image); ?>

	<?php if($id && $image != ''):?>
	<div style="text-align:center; padding:5px; border:1px solid #ccc;"><img src="<?php echo base_url('uploads/'.$image);?>" alt="current"/><br/><?php echo lang('current_file');?></div>
	<?php endif;?>
			
	<div class="form-actions">
		<input class="btn btn-primary" type="submit" value="<?php echo lang('save');?>"/>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(function() {
		$("#enable_on").datepicker({ dateFormat: 'dd-mm-yy'});
		$("#disable_on").datepicker({ dateFormat: 'dd-mm-yy'});
	});
	
	$('form').submit(function() {
		$('.btn').attr('disabled', true).addClass('disabled');
	});
</script>
<?php include('footer.php'); ?>